package com.oj.system.manager;

import com.oj.common.core.constants.CacheConstants;
import com.oj.common.redis.service.RedisService;
import com.oj.system.domain.exam.Exam;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author bin
 * @Date 2025/5/29
 */

@Component
public class ExamCacheManager {

    @Resource
    private RedisService redisService;


    public void addCache(Exam exam){

        // 存到redis中 为提升用户端查询速度
        // key:   e:t:l 未完赛竞赛 value: 中存 examId 的list
        redisService.leftPushForList(CacheConstants.EXAM_TIME_KEY, exam.getExamId());
        // key:   e:h:l  历史竞赛  value: 中存 examId 的list

        // 竞赛的基本信息只储存一份 key: e:d:examId value: 储存每个竞赛信息的json形式
        redisService.setCacheObject(CacheConstants.EXAM_DETAIL_KEY + exam.getExamId(), exam);

    }


    public void deleteCache(Long examId){

        // 将redis中存储的信息删除
        redisService.deleteObject(CacheConstants.EXAM_DETAIL_KEY + examId);

        redisService.removeForList(CacheConstants.EXAM_TIME_KEY, examId);
    }

}
